<?php

namespace app\common\service\platform_manage;


use app\common\service\BaseService;
use think\Db;

class ServerProxyService extends BaseService

{
    /**
     * @name: 获取ip
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-09 13:40:13
     */
    public function getIp ($type)
    {
        $return = Db::name('ServerProxy')->field('ip,port')->where('type', $type)->order('used', 'ASC')->find();

        return $return;
    }

    /**
     * @name 清空当前数据表
     * @return mixed
     * @author wx
     * @date 2019/12/11 13:52
     */
    public function clear()
    {
        $dbConf = config('database.');
        $tableName = $dbConf['prefix'].'server_proxy';

        $clearSql = 'truncate table '.$tableName;
        return Db::query($clearSql);
    }
    /**
     * @name 添加
     * @param $addData
     * @return int|string
     * @author wx
     * @date 2019/12/11 13:48
     */
    public function addAll($addData)
    {
        return Db::name('ServerProxy')->insertAll($addData);
    }

    public function modify($condition, $updateData)
    {
        return Db::name('ServerProxy')->where($condition)->update($updateData);

    }

    /**
     * @name 获取所有代理IP
     * @author wx
     * @date 2019/12/14 13:43
     */
    public function getAllIp()
    {
        return Db::name('ServerProxy')->field('ip')->group('ip')->find();
    }

    public function getCommunicationIp()
    {
        return Db::name('ServerProxy')->field('ip')->where('ip_type',2)->group('ip')->find();
    }
    /**
     * @name: 
     * @Param: 所有代理
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 17:39:04
     */
    public function allProxy ()
    {
        $return = Db::name('ServerProxy')->field('ip,port')->select();

        return $return;
    }
}